﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace WebApp.Web
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{*allaxd}", new { allaxd = @".*\.axd(/.*)?" });
            routes.IgnoreRoute("{*allsvc}", new { allaxd = @".*\.svc(/.*)?" });
            routes.IgnoreRoute("{*allashx}", new { allaxd = @".*\.ashx(/.*)?" });
            routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

            routes.MapRoute(
                name: "Default2",
                url: "manager/html",
                defaults: new { area = "Default", controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

            routes.MapRoute(
                name: "ResizeAsJson",
                url: "Default/Picture/ResizeAsJson/{id}_{width}_{height}",
                defaults: new { area = "Default", controller = "Picture", action = "ResizeAsJson" },
                namespaces: new string[] { "WebApp.Web.Controllers" }
                );

            routes.MapRoute(
               name: "ResizeAs",
               url: "Default/Picture/ResizeAs/{id}_{width}_{height}",
               defaults: new { area = "Default", controller = "Picture", action = "ResizeAs" },
               namespaces: new string[] { "WebApp.Web.Controllers" }
                );


            //更短的网址
            //upload - download
            routes.MapRoute(
                   name: "Upload",
                   url: "Upload",
                   defaults: new { area = "Default", controller = "TempFile", action = "Upload"},
                   namespaces: new string[] { "WebApp.Web.Controllers" }
                    );

            routes.MapRoute(
                   name: "Download",
                   url: "Download",
                   defaults: new { area = "Default", controller = "TempFile", action = "Download"},
                   namespaces: new string[] { "WebApp.Web.Controllers" }
                    );

            //TempCode
            routes.MapRoute(
                   name: "TempCode",
                   url: "{id}",
                   defaults: new { area = "Default", controller = "TempFile", action = "Download" },
                   constraints: new { id = @"[\w|\d]+" },
                   namespaces: new string[] { "WebApp.Web.Controllers" }
                    );

            //Download/...
            //routes.MapRoute(
            //   name: "DownloadAndTempCode",
            //   url: "Download/{id}",
            //   defaults: new { area = "Default", controller = "TempFile", action = "Download", id = UrlParameter.Optional },
            //   namespaces: new string[] { "WebApp.Web.Controllers" }
            //    );


            //必须是 TempFile/Action/....
            //routes.MapRoute(
            //   name: "TempFile",
            //   url: "{action}/{id}",
            //   defaults: new { area = "Default", controller = "TempFile", action = "Index", id = UrlParameter.Optional },
            //   namespaces: new string[] { "WebApp.Web.Controllers" }
            //    );

            //TempFile
            routes.MapRoute(
               name: "Default",
               url: "TempFile/{action}/{id}",
               defaults: new { area = "Default", controller = "TempFile", action = "Index", id = UrlParameter.Optional },
               namespaces: new string[] { "WebApp.Web.Controllers" }
                );


            //全网址
            routes.MapRoute(
                 name: "aca",
                 url: "{area}/{controller}/{action}/{id}",
                 defaults: new { area = "Default", controller = "TempFile", action = "Upload", id = UrlParameter.Optional },
                 namespaces: new string[] { "WebApp.Web.Controllers" }
                  );

        }
    }
}